home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Mac / Demo / cgi / realcgitest.py < prev   
Encoding:
Python Source  |  2000-06-23  |  1.1 KB  |  48 lines

  1. """cgitest - A minimal CGI applet. Echos parameters back to the client.
  2. """
  3.  
  4. from MiniAEFrame import AEServer, MiniApplication
  5.  
  6. class CGITest(AEServer, MiniApplication):
  7.     
  8.     def __init__(self):
  9.         MiniApplication.__init__(self)
  10.         AEServer.__init__(self)
  11.         self.installaehandler('aevt', 'oapp', self.open_app)
  12.         self.installaehandler('aevt', 'quit', self.quit)
  13.         self.installaehandler('WWW\275', 'sdoc', self.cgihandler)
  14.         oldparams = MacOS.SchedParams(0, 0)
  15.         self.mainloop()
  16.         apply(MacOS.SchedParams, oldparams)
  17.  
  18.     def quit(self, **args):
  19.         self.quitting = 1
  20.         
  21.     def open_app(self, **args):
  22.         pass
  23.                 
  24.     def cgihandler(self, pathargs, **args):
  25.         rv = """HTTP/1.0 200 OK
  26. Server: NetPresenz; python-cgi-script
  27. MIME-Version: 1.0
  28. Content-type: text/html
  29.  
  30. <title>Python CGI-script results</title>
  31. <h1>Python CGI-script results</h1>
  32. <hr>
  33. """
  34.         rv = rv+'<br><b>Direct object:</b> %s\n'%pathargs
  35.         
  36.         for key in args.keys():
  37.             if key[0] != '_':
  38.                 rv = rv + '<br><b>%s:</b> %s\n'%(key, args[key])
  39.         rv = rv +'<hr>\nSee you next time!\n'
  40.         
  41.         # Note: if you want to quit after each request enable the line
  42.         # self.quitting = 1
  43.         
  44.         return rv
  45.  
  46. if __name__ == '__main__':
  47.     CGITest()
  48.